home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10387 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.sover.net!news
  2. From: mountain@sover.net (Steve Mount)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting Strings to Upper Case
  5. Date: 17 Mar 1996 14:29:55 GMT
  6. Organization: SoVerNet, Inc.
  7. Message-ID: <4ih7l3$526@thrush.sover.net>
  8. References: <4ifra6$52i@scipio.cyberstore.ca>
  9. NNTP-Posting-Host: pm0a12.mid.sover.net
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <4ifra6$52i@scipio.cyberstore.ca>, ejw@news.cyberstore.ca says...
  15. >I need to write a function to convert a string containg upper or lower case
  16. >characters to the opposite case.  Something like:
  17. >
  18. >  void libConvertUpperCase(char *str);  and
  19. >  void libConvertLowerCase(char *str);
  20. >
  21. >and the string would be modified.  I just can't seem to wrap my head around 
  22. >the best way that I know is better than writing a for loop to check each 
  23. >element in the array?
  24.  
  25. My home compiler has strlwr and strupr functions.  At work, we don't, so
  26. just to make it work, quick and dirty, I did:
  27.  
  28. void strnlwr(char *buffer, int len)
  29. {
  30. register int i;
  31. for (i=0;i<len;i++) buffer[i] = tolower(buffer[i]);
  32. return;
  33. }
  34.  
  35. Note I added a length checker, as this was required; it may not be the most 
  36. efficient, but it gets the job done.  It also prevents me from duplicating
  37. the code that tolower/toupper does.
  38.  
  39. +============================================================================+
  40. | Steve Mount, Software Engineer            Work: sjjm@hawkeye.idx.com       |
  41. | CIS: 73720,3404  MSN: S_Mountain          Home: mountain@sover.net         |
  42. | AOL: Mountain                                                              |
  43. | WWW: http://www.sover.net/~mountain/      "Fight, Win, Prevail!"           |
  44. +============================================================================+
  45.  
  46.